package com.tedu.weibo.common.result;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

/**
 *  统一结果响应
 *  规范Controller的返回值
 *  格式由JSON对象表示，对应的属性
 *  int status: 响应状态码
 *  String msg: 描述响应结果
 *  Object data: 响应数据
 */
@Getter
@Setter
// 全参构造函数
@AllArgsConstructor
// 无参构造函数
@NoArgsConstructor
public class JsonResult {
    private Integer status;
    private String msg;
    private Object data;

    public JsonResult(StatusCode statusCode) {
        this.status = statusCode.getStatusCode();
        this.msg = statusCode.getMessage();
    }
    public JsonResult(StatusCode statusCode, Object data) {
        // 调用本类的构造器 JsonResult(StatusCode statusCode)
        this(statusCode);
        this.data = data;
    }

    public static JsonResult success(Object data) {
        return new JsonResult(StatusCode.OPERATION_SUCCESS,data);
    }

    public static JsonResult success() {
        return success(null);
    }

}


























